package com.rm.freedrawview;

import ohos.agp.render.Paint;
import ohos.utils.Parcel;
import ohos.utils.Sequenceable;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * Created by Riccardo Moro on 11/4/2016.
 *
 * @author author
 * @version 1.0.0
 */
class FreeDrawSavedState implements Sequenceable, Serializable {
    private ArrayList<HistoryPath> mPaths = new ArrayList<>();
    private ArrayList<HistoryPath> mCanceledPaths = new ArrayList<>();

    private int mPaintColor;
    private int mPaintAlpha;
    private float mPaintWidth;

    private ResizeBehaviour mResizeBehaviour;

    private int mLastDimensionW;
    private int mLastDimensionH;

    FreeDrawSavedState(
            ArrayList<HistoryPath> paths, ArrayList<HistoryPath> canceledPaths,
            float paintWidth, int paintColor, int paintAlpha,
            ResizeBehaviour resizeBehaviour, int lastDimensionW, int lastDimensionH) {
        mPaths = paths;
        mCanceledPaths = canceledPaths;
        mPaintWidth = paintWidth;
        mPaintColor = paintColor;
        mPaintAlpha = paintAlpha;
        mResizeBehaviour = resizeBehaviour;
        mLastDimensionW = lastDimensionW;
        mLastDimensionH = lastDimensionH;
    }

    ArrayList<HistoryPath> getPaths() {
        return mPaths;
    }

    ArrayList<HistoryPath> getCanceledPaths() {
        return mCanceledPaths;
    }

    int getPaintColor() {
        return mPaintColor;
    }

    int getPaintAlpha() {
        return mPaintAlpha;
    }

    float getCurrentPaintWidth() {
        return mPaintWidth;
    }

    Paint getCurrentPaint() {
        Paint paint = FreeDrawHelper.createPaint();
        FreeDrawHelper.setupStrokePaint(paint);
        FreeDrawHelper.copyFromValues(paint, mPaintColor, mPaintAlpha, mPaintWidth, true);
        return paint;
    }

    ResizeBehaviour getResizeBehaviour() {
        return mResizeBehaviour;
    }

    int getLastDimensionW() {
        return mLastDimensionW;
    }

    int getLastDimensionH() {
        return mLastDimensionH;
    }

    @Override
    public boolean marshalling(Parcel out) {
        out.writeInt(mPaintColor);
        out.writeInt(mPaintAlpha);
        out.writeInt(mLastDimensionW);
        out.writeInt(mLastDimensionH);
        out.writeFloat(mPaintWidth);
        out.writeSerializable(mResizeBehaviour);
        out.writeSequenceableList(mPaths);
        out.writeSequenceableList(mCanceledPaths);
        return true;
    }

    @Override
    public boolean unmarshalling(Parcel parcel) {
        mPaintColor = parcel.readInt();
        mPaintAlpha = parcel.readInt();
        mLastDimensionW = parcel.readInt();
        mLastDimensionH = parcel.readInt();
        mPaintWidth = parcel.readFloat();
        mResizeBehaviour = parcel.readSerializable(ResizeBehaviour.class);
        mPaths = (ArrayList<HistoryPath>) parcel.readSequenceableList(HistoryPath.class);
        mCanceledPaths = (ArrayList<HistoryPath>) parcel.readSequenceableList(HistoryPath.class);
        return true;
    }
}
